/*
 *  您可以更改此项目但请不要删除作者署名谢谢，否则根据中华人民共和国版权法进行处理.
 *  You may change this item but please do not remove the author's signature,
 *  otherwise it will be dealt with according to the Copyright Law of the People's Republic of China.
 *
 *  如果需要联系到我请加Wechat: yangbuyiya 备注交流学习
 *  If you need to contact me, please add Wechat: yangbuyiya as a note to exchange and learn.
 *  yangbuyi Copyright (c) https://yby6.com 2024.
 */

package com.yby6.controller;


import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.yby6.req.vo.ChatYuanQiRequestVo;
import com.yby6.resp.dto.ChatYuanQiRequestDto;
import com.yby6.resp.R;
import com.yby6.service.AudioService;
import com.yby6.utils.TencentUtils;
import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.core.handle.MethodType;

/**
 * 多智能体问答
 *
 * @author Yang Shuai
 * Create By 2024/06/26
 */
@Controller
@Mapping("v1")
public class ChatCompletionController {
    
    @Inject
    private AudioService audioService;
    
    /**
     * 元器智能体问答
     * <p>
     * 支持传递音频Base64文件
     * 支持传递普通文本
     * </p>
     *
     * @param chatYuanQiRequestVo 问答聚合
     * @return {@link ChatYuanQiRequestDto} 聚合返回参数
     */
    @Mapping(value = "chatCompletion", method = MethodType.POST)
    public R<ChatYuanQiRequestDto> chatCompletion(@Body ChatYuanQiRequestVo chatYuanQiRequestVo) {
        return R.ok(audioService.chatCompletion(chatYuanQiRequestVo));
    }
    
    /**
     * 录音文件识别 - 语音转文字
     */
    @Mapping(value = "voiceTotext", method = MethodType.POST)
    public R voiceTotext(@Body ChatYuanQiRequestVo chatYuanQiRequestVo) throws TencentCloudSDKException {
        return R.ok(TencentUtils.voiceToText(chatYuanQiRequestVo.getAudioFile()));
    }
    
}
